//
//  RegisteredVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/29.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "RegisteredVC.h"
#import "VerificationCodeVC.h"
#import "LoginVM.h"
@interface RegisteredVC ()
@property (weak, nonatomic) IBOutlet QXTextField *textAccount;
@property (weak, nonatomic) IBOutlet QXTextField *textPassword;
@property (weak, nonatomic) IBOutlet UIButton *btnNext;
@property (weak, nonatomic) IBOutlet QXTextField *textUserName;
@property (weak, nonatomic) IBOutlet QXTextField *textInviteCode;

@end

@implementation RegisteredVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"用户注册";
    self.view.backgroundColor=[UIColor whiteColor];
    _btnNext.layer.cornerRadius=25;
    _btnNext.layer.masksToBounds=YES;
    // Do any additional setup after loading the view.
}

- (IBAction)next:(UIButton *)sender {
    if (_textAccount.text.length!=11) {
        [SVProgressHUD showErrorWithStatus:@"请输入正确的手机号码"];
        return;
    }
    if (_textPassword.text.length<6||_textPassword.text.length>16) {
        [SVProgressHUD showErrorWithStatus:@"密码位数不对"];
        return;
    }
    if (_textUserName.text.length<1) {
        [SVProgressHUD showErrorWithStatus:@"请输入您的用户昵称"];
        return;
    }
    if (_textUserName.text.length>=8) {
        [SVProgressHUD showErrorWithStatus:@"昵称最多7个字"];
        return;
    }
    sender.userInteractionEnabled=NO;
    WS(weakSelf);
    [[LoginVM manage] validateWithMobile:_textAccount.text andSuccess:^(id returnValue) {
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:_textAccount.text,@"Phone",_textPassword.text,@"Password",_textUserName.text,@"NickName",[NSNumber numberWithInteger:[_textInviteCode.text integerValue]],@"InviteCode", nil];
        VerificationCodeVC *vc=[[UIStoryboard storyboardWithName:@"CLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"VerificationCodeVC"];
        vc.userInfo=dict;
        vc.type=VerificationCodeTypeRegistered;
        [weakSelf.navigationController pushViewController:vc animated:YES];
        sender.userInteractionEnabled=YES;
    } andFail:^(NSString *errorMessage, NSError *error) {
        sender.userInteractionEnabled=YES;
        if ([errorMessage integerValue]==50000) {
            [SVProgressHUD showErrorWithStatus:@"手机号码已存在"];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
